package xhwl.insurance.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import xhwl.android.common.util.StringUtil;
import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.MessageResp;

/**
 * Created by fuyi on 2017/8/24.
 */

public class MessageCenterAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<MessageResp> mList;


    public MessageCenterAdapter(Context context, ArrayList<MessageResp> mList) {
        this.mContext = context;
        this.mList = mList;

    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder mHolder;

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_message_center, null);
            mHolder = new ViewHolder();
            mHolder.mTitle = (TextView) convertView.findViewById(R.id.tv_message_title);
            mHolder.mContent = (TextView) convertView.findViewById(R.id.tv_message_content);
            mHolder.mDate= (TextView) convertView.findViewById(R.id.tv_message_date);
            mHolder.mIcon=(ImageView)convertView.findViewById(R.id.iv_message);

            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        String title=mList.get(position).PUSH_TITLE;
        if(StringUtil.isEmpty(title)){
            title="通知";
        }
        if (title.equals("版本通知")){
            mHolder.mIcon.setImageResource(R.drawable.icon_banben);
        }else if (title.equals("系统通知")){
            mHolder.mIcon.setImageResource(R.drawable.system_icon);
        }
        if("0".equals(mList.get(position).READ_IF)){//未读
            mHolder.mTitle.setTextColor(mContext.getResources().getColor(R.color.text_color_33));
            mHolder.mContent.setTextColor(mContext.getResources().getColor(R.color.text_color_66));
            mHolder.mDate.setTextColor(mContext.getResources().getColor(R.color.text_color_66));
        }
        else
        {
            mHolder.mTitle.setTextColor(mContext.getResources().getColor(R.color.text_color_99));
            mHolder.mContent.setTextColor(mContext.getResources().getColor(R.color.text_color_99));
            mHolder.mDate.setTextColor(mContext.getResources().getColor(R.color.text_color_99));
        }
        mHolder.mTitle.setText(title);
        mHolder.mContent.setText(mList.get(position).PUSH_CONTENT);
        mHolder.mDate.setText(mList.get(position).CREATE_DATE);

        return convertView;
    }

    static class ViewHolder {
        private TextView mDate;
        private TextView mTitle;
        private TextView mContent;
        ImageView mIcon;
    }

}
